home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / metamail / st / RFC-SAFE-TCL.txt < prev    next >
Encoding:
Text File  |  1993-05-13  |  70.6 KB  |  1,654 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                    MIME Extensions for Mail-Enabled Applications:
  9.  
  10.                   application/Safe-Tcl and multipart/enabled-mail
  11.  
  12.  
  13.  
  14.                            Nathaniel Borenstein, Bellcore
  15.                         Marshall Rose, Dover Beach Consulting
  16.  
  17.                                      May, 1993
  18.  
  19.           Status of this Memo
  20.  
  21.             This document is a working draft.  Do  not  cite,  copy,  or
  22.             circulate.
  23.  
  24.           Abstract
  25.  
  26.             MIME [RFC-MIME] defines a format and general  framework  for
  27.             the  representation  of  a  wide  variety  of  data types in
  28.             Internet mail.  This document defines two  new  subtypes  of
  29.             MIME  data,  the application/Safe-Tcl and multipart/enabled-
  30.             mail subtypes, for providing enabled mail [EM-MODEL] in  the
  31.             Internet community.
  32.  
  33.             A table of contents appears at the end of this document.
  34.  
  35.             1.  Overview
  36.  
  37.             Most electronic mail, even multimedia mail  as  standardized
  38.             in  MIME [RFC-MIME], is "passive" in the sense that the data
  39.             are unidirectional.  Textual, image, audio,  or  video  data
  40.             are simply displayed to the user, who reads, views, listens,
  41.             or watches it and then must take specific action to initiate
  42.             any   response  to  the  data,  such  as  to  reply  to  the
  43.             originator, to replay the data, or  to  redistribute  it  to
  44.             other recipients.
  45.  
  46.             Less commonly used, but the subject of considerable research
  47.             attention,  has  been  "active"  mail,  in  which  the  data
  48.             delivered through the mail constitute a program in  a  well-
  49.             specified language, allowing the program to be automatically
  50.             evaluated on behalf  of  the  recipient  when  the  mail  is
  51.             "read."      Researchers   have   demonstrated   fascinating
  52.             applications of this concept, and in recent years have shown
  53.  
  54.  
  55.  
  56.             Borenstein/Rose  Mail-Enabled Applications            Page 1
  57.  
  58.  
  59.  
  60.  
  61.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [2]
  62.  
  63.  
  64.             that  the critical problems of safety and portability can be
  65.             solved in a straightforward manner [ATOMICMAIL].
  66.  
  67.             This  memo   defines   a   standardized   format   for   the
  68.             interoperation  of  active  mail in the context of MIME.  It
  69.             defines a new  language,  "Safe-Tcl",  based  on  the  "Tcl"
  70.             language  [TCL].   It  also  defines a new MIME content-type
  71.             value, "application/Safe-Tcl", which may be used  to  tag  a
  72.             MIME entity (a mail body or body part) as being a program in
  73.             the Safe-Tcl language.    Additionally, this memo defines  a
  74.             new   multipart   subtype,   "multipart/enabled-mail",   for
  75.             grouping  together  an  interactive  mail  program  and   an
  76.             arbitrary MIME entity to which it is related.
  77.  
  78.             The reader should consult [EM-MODEL] for  a  description  of
  79.             the  basic  Enabled Mail model, which is not presented here.
  80.             This memo also does not provide a  tutorial  in  either  the
  81.             fundamental  problems  of  safety  and portability in active
  82.             messaging,  which  the  interested  reader   may   find   in
  83.             [ATOMICMAIL].   Nor does this memo provide a tutorial in the
  84.             Tcl language itself, for  which  the  interested  reader  is
  85.             referred to [TCL].
  86.  
  87.             This memo assumes a basic familiarity  with  the  syntax  of
  88.             Tcl,  and  defines Safe-Tcl in terms of its differences from
  89.             standard Tcl.  The resulting language  is  believed  by  the
  90.             authors to be safe for email use, according to the reasoning
  91.             outlined in [ATOMICMAIL]. In particular, it is the intent of
  92.             the  Safe-Tcl  language design that it should be essentially
  93.             harmless to evaluate a Safe-Tcl program that comes  from  an
  94.             unknown or hostile sender.
  95.  
  96.             2.  The application/Safe-Tcl content-type
  97.  
  98.             The language defined in this memo shall  be  labelled  as  a
  99.             MIME  body or body part by the use of the "application/Safe-
  100.             Tcl" content-type.  Two  mandatory  content-type  parameters
  101.             are  defined  for  this  content-type.  The first parameter,
  102.             "version",  is a version number for  the  Safe-Tcl  language
  103.             itself.   For  the version of Safe-Tcl defined in this memo,
  104.             the version value should be "6.8".   The  second  parameter,
  105.             "evaluation-time",  is a string describing the intended time
  106.             of evaluation for the Safe-Tcl program.  Thus  the  content-
  107.             type line might look something like this:
  108.  
  109.  
  110.  
  111.  
  112.  
  113.             Borenstein/Rose  Mail-Enabled Applications            Page 2
  114.  
  115.  
  116.  
  117.  
  118.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [3]
  119.  
  120.  
  121.                  Content-type: application/Safe-Tcl; version="6.8";
  122.                          evaluation-time=activation
  123.  
  124.             The choice of "6.8" is  indicative  of  the  fact  that  the
  125.             Safe-Tcl  language,  as  described here, is derived from Tcl
  126.             version 6.8.  However, this should NOT be taken to  indicate
  127.             that  arbitrary  other  versions  of  Tcl may be used with a
  128.             corresponding change to the version parameter.  If a  future
  129.             version  of  Safe-Tcl  is  ever defined, it will be formally
  130.             specified and published as part of the MIME process.  It  is
  131.             explicitly  NOT  the case that arbitrary versions of Tcl may
  132.             be used with a suitably modified version parameter.
  133.  
  134.             The evaluation-time parameter may have one  of  two  values,
  135.             "delivery"   or   "activation",  which  corresponds  to  the
  136.             delivery-time and activation-time  phases  defined  in  [EM-
  137.             MODEL].  A  value  of "activation" means that the program is
  138.             intended  to  be  evaluated  whenever  the  user  views  the
  139.             message, and may need to interact with the user.  A value of
  140.             "delivery"  means  that  the  program  is  intended  to   be
  141.             evaluated  upon  final  delivery  to the user's mailbox, and
  142.             cannot interact  directly  with  the  user,  though  it  may
  143.             interact with user-supplied Safe-Tcl extensions.
  144.  
  145.             Note that a MIME message that contains an  application/safe-
  146.             tcl entity with an evaluation-time of "delivery" is intended
  147.             to be evaluated at delivery time.  Such an entity will  ONLY
  148.             be evaluated, however, if it appears as either the top-level
  149.             MIME content-type or a second-level type, directly inside  a
  150.             multipart/enabled-mail     entity.      A     nested    MIME
  151.             application/safe-tcl  entity  with  an  evaluation-time   of
  152.             "delivery" should be ignored.
  153.  
  154.             3.  The multipart/enabled-mail content-type
  155.  
  156.             This memo defines  a  new  subtype  of  the  MIME  multipart
  157.             content-type,           "multipart/enabled-mail".          A
  158.             multipart/enabled-mail  entity   will   have   exactly   two
  159.             subparts,  the first of which will be of arbitrary type, and
  160.             the second of which will be of type application/Safe-Tcl (or
  161.             some future language for enabled mail).
  162.  
  163.             The  intended  semantics  of  multipart/enabled-mail,   when
  164.             viewed  by  a  human reader, are as follows:  If there is no
  165.             application/Safe-Tcl  interpreter  available,  or   if   the
  166.             application/Safe-Tcl part has an evaluation-time of anything
  167.  
  168.  
  169.  
  170.             Borenstein/Rose  Mail-Enabled Applications            Page 3
  171.  
  172.  
  173.  
  174.  
  175.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [4]
  176.  
  177.  
  178.             other than "activation", then the Safe-Tcl program should be
  179.             skipped  and the first part, an abitrary MIME entity, should
  180.             be displayed normally.  If, however,  the  Safe-Tcl  program
  181.             has   an  evaluation-time  of  activation,  and  a  Safe-Tcl
  182.             interpreter is available, then the Safe-Tcl  program  should
  183.             be  evaluated  and  the first part of the multipart/enabled-
  184.             mail object should NOT be displayed.  (Parts of it, however,
  185.             may  have  been  displayed under the control of the Safe-Tcl
  186.             program.)
  187.  
  188.             4.  The Safe-Tcl Language
  189.  
  190.             The syntax of Safe-Tcl is identical to  the  syntax  of  Tcl
  191.             [TCL].   No  syntactic  constructs  are  changed.   The only
  192.             differences, therefore, between Tcl and Safe-Tcl is the  set
  193.             of  available  primitive functions and procedures.  Safe-Tcl
  194.             may be described as an "extended subset" of Tcl, in that the
  195.             "dangerous"  primitives  in  Tcl  have  been  removed, while
  196.             certain new primitives have been added.
  197.  
  198.             It is assumed that the process evaluating a Safe-Tcl  script
  199.             will  always  have  within it TWO interpreters, one for full
  200.             Tcl and one for Safe-Tcl.  A correct implementation will not
  201.             let  a  program  being evaluated by the Safe-Tcl interpreter
  202.             have access to the  full  Tcl  interpreter  except  via  the
  203.             mechanisms defined as part of the Safe-Tcl language.
  204.  
  205.             4.1.  The Core Safe-Tcl Language
  206.  
  207.             Because Tcl is an evolving language, it  is  not  considered
  208.             sufficient  to  describe  Safe-Tcl  completely  in  terms of
  209.             differences from this base, as this  may  prove  dangerously
  210.             confusing  if some future version of the language includes a
  211.             potentially dangerous primitive not mentioned in the list of
  212.             differences.   Therefore, this memo provides a complete list
  213.             of all the Safe-Tcl  primitives  "inherited"  from  standard
  214.             Tcl.   No  other primitives should be provided by a Safe-Tcl
  215.             interpreter.  As a convenience to the reader, this memo will
  216.             also  list the standard Tcl primitives that were consciously
  217.             omitted  from  Safe-Tcl,  but  this  list  should   not   be
  218.             considered exhaustive, in that any Tcl primitive that is not
  219.             explicitly mentioned as being part  of  Safe-Tcl  should  be
  220.             considered NOT to be part of Safe-Tcl.
  221.  
  222.             In particular,  the  following  standard  Tcl  commands  are
  223.             considered  unsafe  or  inappropriate for email use, and are
  224.  
  225.  
  226.  
  227.             Borenstein/Rose  Mail-Enabled Applications            Page 4
  228.  
  229.  
  230.  
  231.  
  232.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [5]
  233.  
  234.  
  235.             NOT to be interpreted by Safe-Tcl interpreters:
  236.  
  237.                  auto_execok, auto_load, auto_mkindex,  auto_reset,
  238.                  cd,  close,  eof,  exec,  file, flush, gets, glob,
  239.                  open, puts, pwd, read, seek, source, tell
  240.  
  241.             The core set of standard Tcl commands which ARE  a  part  of
  242.             the Safe-Tcl language are:
  243.  
  244.                  append,  array,  break,   case,   catch,   concat,
  245.                  continue,  error,  eval, exit, expr, for, foreach,
  246.                  format, global, history,  if,  incr,  info,  join,
  247.                  lappend,  lindex,  linsert, list, llength, lrange,
  248.                  lreplace, lsearch, lsort,  proc,  regexp,  regsub,
  249.                  rename,  return,  scan,  set, split, string, time,
  250.                  trace, unknown, unset, uplevel, upvar, while
  251.  
  252.             The core  Safe-Tcl  language  also  includes  the  following
  253.             global variables from standard Tcl:
  254.  
  255.                  errorCode, errorInfo
  256.  
  257.             Other global variables might  be  defined  as  needed  by  a
  258.             Safe-Tcl  interpreter,  but  their  presence  should  not be
  259.             relied on.
  260.  
  261.             In   addition,   Safe-Tcl   includes   additional   built-in
  262.             procedures  and variables that are NOT part of standard Tcl,
  263.             defined in the sections that  follow.   Some  of  these  are
  264.             available   to  all  Safe-Tcl  programs,  while  others  are
  265.             available only with certain values  of  the  evaluation-time
  266.             parameter or in certain user interface environments.
  267.  
  268.             4.2.  Universal Safe-Tcl Functionality
  269.  
  270.             The following primitves are  always  part  of  the  Safe-Tcl
  271.             language.
  272.  
  273.                  SafeTcl_getconfigdata  --  "SafeTcl_getconfigdata   key
  274.                       ?default  ?prompt?".  To permit user customization
  275.                       of Safe-Tcl applications in  the  absence  of  any
  276.                       generalized  file system access, Safe-Tcl includes
  277.                       a mechanism for associating a customization string
  278.                       with  a  key string.  SafeTcl_getconfigdata should
  279.                       return the string value associated with  the  key,
  280.                       and  should  generate  an  error  if  this  is not
  281.  
  282.  
  283.  
  284.             Borenstein/Rose  Mail-Enabled Applications            Page 5
  285.  
  286.  
  287.  
  288.  
  289.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [6]
  290.  
  291.  
  292.                       possible.   If  the  user   has   not   previously
  293.                       specified  the customization value (which might be
  294.                       done by  a  mechanism  that  is  specific  to  the
  295.                       particular  Safe-Tcl  interpreter),  the  Safe-Tcl
  296.                       interpreter should engage the user in a dialog  to
  297.                       obtain  the  value, which should then be saved for
  298.                       future use.  In this case, the optional second and
  299.                       third  arguments  provide  a  default  value and a
  300.                       prompt to explain the nature of the data needed to
  301.                       the  user.   If the user HAS previously supplied a
  302.                       customization value to the user, then  whether  or
  303.                       not   any   user   action   is   invoked   by  the
  304.                       SafeTcl_getconfigdata         primitive         is
  305.                       implementation-dependent,  but  a suggested action
  306.                       is to  use  the  previously-supplied  value  as  a
  307.                       default  and  to ask the user to confirm that this
  308.                       is still the correct  value.   Note  that  if  the
  309.                       evaluation-time    is    "delivery",    any   user
  310.                       interaction  is  impossible.   In  this  case,  if
  311.                       user-supplied data is available it should be used,
  312.                       and otherwise an error should be generated.
  313.  
  314.                  SafeTcl_random--  "SafeTcl_random   min   max".    This
  315.                       primitive   returns  a  pseudo-randomly  generated
  316.                       integer greater than or equal to the  integer  min
  317.                       and less than or equal to the integer max.  If min
  318.                       is  equal  to  max,  that  value  will  always  be
  319.                       returned.   If  min  is greater than max, an error
  320.                       will be generated.
  321.  
  322.                  SafeTcl_encryptstring --  "SafeTcl_encryptstring string
  323.                       algorithm   key".   This  primitive  encrypts  the
  324.                       string supplied as the first  argument  using  the
  325.                       algorithm specified by a string name in the second
  326.                       argument and the encryption key  provided  as  the
  327.                       third  argument.  The encrypted value is returned.
  328.                       If encryption is  not  implemented  or  cannot  be
  329.                       performed  for  any  reason (such as international
  330.                       export controls), an error will be generated.  The
  331.                       string   names  to  be  used  for  algorithms  are
  332.                       registered with the IANA and documented elsewhere.
  333.                       An  algorithm  name starting with "x-" may be used
  334.                       by private agreement.
  335.  
  336.             Additionaly, Safe-Tcl always defines a global variable  that
  337.             indicates the current evaluation-time context:
  338.  
  339.  
  340.  
  341.             Borenstein/Rose  Mail-Enabled Applications            Page 6
  342.  
  343.  
  344.  
  345.  
  346.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [7]
  347.  
  348.  
  349.                  SafeTcl_evaluation_time -- A  string  that  is  set  to
  350.                       either  "delivery" or "activation" to indicate the
  351.                       current evaluation-time context.
  352.             4.3.  Additional Messaging Functionality
  353.  
  354.             The following primitives are always  part  of  the  Safe-Tcl
  355.             language  when  used  in the context of MIME, but may not be
  356.             present if the language is adopted for non-email use.
  357.  
  358.             Note  that  four  of  these  procedures  (SafeTcl_getheader,
  359.             SafeTcl_getheaders,         SafeTcl_getbodyprop,         and
  360.             SafeTcl_getparts) may make  implicit  reference  to  a  MIME
  361.             message.   Each of them has an optional parameter, specified
  362.             here as "?body?", which may contain a MIME entity.  If  this
  363.             optional  parameter  is  not  supplied, then, in the case of
  364.             evaluation-time "delivery", the ?body? is assumed to be  the
  365.             entire  MIME  message  that  has just been delivered. In the
  366.             case  of  evaluation-time  "activation",  if  the   Safe-Tcl
  367.             program  is  part  of  a multipart/enabled-mail MIME entity,
  368.             then the ?body? is assumed to be  the  OTHER  part  of  that
  369.             multipart/enabled-mail  entity.   In the case of evaluation-
  370.             time "activation" when the Safe-Tcl program is NOT part of a
  371.             multipart/enabled-mail  message,  an error will be generated
  372.             if an explicit body is not provided as a string argument.
  373.  
  374.                  SafeTcl_getaddrs --  "SafeTcl_getaddrs  string".   This
  375.                       returns  a list, each element of which is a string
  376.                       containing an electronic mail address found in the
  377.                       argument.
  378.  
  379.                  SafeTcl_getaddrprop  --  "SafeTcl_getaddrprop   address
  380.                       property".   This  returns  the specified property
  381.                       from the address string. Properties are:
  382.  
  383.                       Property   Returns Description
  384.                       --------   ------- -----------
  385.                       proper     string  official 822 rendering,
  386.                                          e.g. "phrase <local@domain>"
  387.                       friendly   string   user-friendly  rendering  (see
  388.                            Appendix C)
  389.                       address    string  local@domain rendering
  390.                       phrase     string  the phrase part
  391.                       local      string  the local part
  392.                       mymbox     integer "1" if this is the  recipient's
  393.                            address,
  394.  
  395.  
  396.  
  397.  
  398.             Borenstein/Rose  Mail-Enabled Applications            Page 7
  399.  
  400.  
  401.  
  402.  
  403.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [8]
  404.  
  405.  
  406.                                            as   determined   by    local
  407.                            configuration,
  408.                                          "0" otherwise.
  409.                       domain     string  the domain part
  410.  
  411.                       If the string can not be parsed as a mail address,
  412.                            an error should be generated.
  413.  
  414.                  SafeTcl_getdateprop   --   "SafeTcl_getdateprop    date
  415.                       property".   This  returns  the specified property
  416.                       from  the   date   string,   which   is   a   date
  417.                       specification  in  RFC 822/1123 format. Properties
  418.                       are:
  419.  
  420.                       Property   Returns Description
  421.                       --------   ------- -----------
  422.                       sec        integer seconds of the minute
  423.                       min        integer minutes of the hour
  424.                       hour       integer hours of the day (0-23)
  425.                       wday       integer day of the week (Sun=0)
  426.                       day        string  day of the week
  427.                                          (3 char abbreviation)
  428.                       weekday    string  day of the week
  429.                       sday       integer day of the week known?
  430.                                              (1=explicit     0=implicit,
  431.                            -1=unknown)
  432.                       mday       integer day of the month
  433.                       yday       integer day of the year
  434.                       mon        integer month of the year
  435.                       month      string  month of the year
  436.                                          (3 char abbreviation)
  437.                       lmonth     string  month of the year
  438.                       year       integer year (all digits, e.g. 1993)
  439.                       zone       integer timezone in hours
  440.                       tzone      string  timezone string
  441.                       szone      integer timezone known?
  442.                                             (1=explicit,     0=implicit,
  443.                            -1=unknown)
  444.                       date2local string  coerce date to local timezone
  445.                       date2gmt   string  coerce date to GMT
  446.                       dst        integer daylight savings in effect?
  447.                       rclock     integer seconds prior to current time
  448.                       proper     string  official 822 rendering
  449.  
  450.                       If the string can not be  parsed  as  a  date,  an
  451.                       error  should be generated.  If the date specified
  452.  
  453.  
  454.  
  455.             Borenstein/Rose  Mail-Enabled Applications            Page 8
  456.  
  457.  
  458.  
  459.  
  460.             Borenstein/Rose  Mail-Enabled Applications      May 1993 [9]
  461.  
  462.  
  463.                       is the empty string, the  current  date  and  time
  464.                       should be used.
  465.  
  466.                  SafeTcl_getheader -- "SafeTcl_getheader field  ?body?".
  467.                       This returns the value of a field in the message's
  468.                       (or MIME entity's) headers. If the  field  is  not
  469.                       present   in  the  headers,  the  null  string  is
  470.                       returned. If the header  field  occurs  more  than
  471.                       once  in  the  headers,  the associated values are
  472.                       concatenated together according to  the  rules  of
  473.                       RFC 822 (e.g., the values associated with multiple
  474.                       occurrences  of  a  header  field  which  contains
  475.                       addresses are concatenated with a comma).
  476.  
  477.                  SafeTcl_getheaders   --  "SafeTcl_getheaders   ?body?".
  478.                       This  returns  an  array  of  lists, each of which
  479.                       identifies a header field contained in the message
  480.                       (or  MIME  entity). (The SafeTcl_getheader routine
  481.                       can be used to extract the value  associated  with
  482.                       each  header field.)   Each of these lists has two
  483.                       string elements, the first of which  is  a  header
  484.                       field  name,  and  the second of which is a header
  485.                       field body.  If the MIME entitiy contains multiple
  486.                       header fields with the same name, each will appear
  487.                       as a different list.
  488.  
  489.                  SafeTcl_makebody -- "SafeTcl_makebody  content-type  [-
  490.                       parameter  string]   [-description  string] [value
  491.                       encoding] ...".  This creates a MIME entity of the
  492.                       specified  content-type.  (If  the empty string is
  493.                       given  as  the  content-type,    "text/plain"   is
  494.                       assumed.)   The  "-parameter  string" sequence may
  495.                       occur zero or  more  times  to  indicate  whatever
  496.                       parameters  are  associated with the content type.
  497.                       The "-description string" sequence  may  occur  at
  498.                       most   once  to  specify  the  content-description
  499.                       field.  For a multipart  content,  each  remaining
  500.                       parameter   describes   a  subordinate  body-part.
  501.                       Otherwise,  only  one   remaining   parameter   is
  502.                       present,  which  specifes the data associated with
  503.                       the body.  Each body is described as a  list,  the
  504.                       first  element of which is the data value, and the
  505.                       second element of which is a string describing any
  506.                       content-transfer-encoding  algorithm that has been
  507.                       applied (i.e. "base64" or "quoted-printable" or ""
  508.                       for   no  encoding).   If  no  encoding  has  been
  509.  
  510.  
  511.  
  512.             Borenstein/Rose  Mail-Enabled Applications            Page 9
  513.  
  514.  
  515.  
  516.  
  517.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [10]
  518.  
  519.  
  520.                       applied, the second element may  be  omitted  from
  521.                       the list describing the body-part.
  522.  
  523.                  SafeTcl_getparts --  "SafeTcl_getparts  ?body?".   This
  524.                       returns  a  list,  each  element being a list that
  525.                       identifies a MIME entity contained within the body
  526.                       parameter.  Each  of  these  lists  consists  of a
  527.                       numeric  identifier,   a   content-type,   and   a
  528.                       content-description  string.   The return value is
  529.                       constructed by a pre-order traversal of the  body,
  530.                       with  the  prefix  of  a  subordinate entity being
  531.                       copied  from  its  parent.  For  example,  if  the
  532.                       structure of a message were:
  533.  
  534.                       multipart/mixed
  535.                         text/plain
  536.                         multipart/digest
  537.                           message/rfc822
  538.                         audio/basic
  539.  
  540.                       then the list returned would have this structure:
  541.  
  542.                       [["1" "multipart/mixed" "A bunch of stuff"]
  543.                          ["1.1" "text/plain" "Introduction"]
  544.                          ["1.2" "multipart/digest" "Today's news"]
  545.                            ["1.2.1" "message/rfc822" "A word from Bill"]
  546.                          ["1.3" "audio/basic" "Many words from Bill"]]
  547.  
  548.                  SafeTcl_getbodyprop  --  "SafeTcl_getbodyprop  property
  549.                       part  ?body?".   Returns  a  string containing the
  550.                       value of the  specified  property  for  body  part
  551.                       specified  by  the  second  and  third parameters.
  552.                       Properties are:
  553.  
  554.                       Property   Returns Description
  555.                       --------   ------- -----------
  556.                       type       string  value of Content-Type field
  557.                                          (without parameters)
  558.                       parms      list    each element a parameter from
  559.                                          the Content-Type field, given
  560.                                          as a list of two items
  561.                                          [paramname paramvalue]
  562.                       id         string  value of Content-ID field
  563.                       descr      string  value of Content-Description
  564.  
  565.  
  566.  
  567.  
  568.  
  569.             Borenstein/Rose  Mail-Enabled Applications           Page 10
  570.  
  571.  
  572.  
  573.  
  574.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [11]
  575.  
  576.  
  577.                                          field
  578.                       value      string  data value, possibly encoded
  579.                       encoding   string  "base64", "quoted-printable",
  580.                                          or "" (where "7bit", "8bit",
  581.                                          or "binary" was used)
  582.  
  583.  
  584.                  SafeTcl_encode -- "SafeTcl_encode encoding data".  This
  585.                       takes  the specified data and encodes it according
  586.                       to the  MIME  encoding  specified  by  the  encode
  587.                       argument,  which must be either "quoted-printable"
  588.                       or "base64".  It returns  a  string  that  is  the
  589.                       encoded data.
  590.  
  591.                  SafeTcl_decode -- "SafeTcl_decode encoding data".  This
  592.                       takes  the  specified  encoded data and decodes it
  593.                       according to the MIME encoding  specified  by  the
  594.                       encode  argument,  which  must  be either "quoted-
  595.                       printable" or "base64".  It returns a string  that
  596.                       is the decoded data.
  597.  
  598.             4.4.  Additional Delivery-Time Functionality
  599.  
  600.             When a Safe-Tcl program is delivered in a mail message  with
  601.             the  evaluation-time  parameter given as "delivery", then no
  602.             interaction with a user is possible.  In this  context,  two
  603.             additional global variables are available:
  604.  
  605.                  SafeTcl_originator   --   A   string   containing   the
  606.                       originator  of  the  message,  as indicated by the
  607.                       envelope.
  608.  
  609.                  SafeTcl_recipient -- A string containing the  recipient
  610.                       of the message, as indicated by the envelope.
  611.  
  612.             Also, the following additional procedures are defined:
  613.  
  614.                  SafeTcl_getmessagelength -- "SafeTcl_getmessagelength".
  615.                       This  function, which takes no arguments returns a
  616.                       string giving the length of the message in octets,
  617.                       including the message headers.
  618.                        The way that CRLF pairs  are  counted,  for  this
  619.                       purpose,  is  implementation-dependent, but should
  620.                       be  consistent  with  the  way  SafeTcl_getmessage
  621.                       functions.
  622.  
  623.  
  624.  
  625.  
  626.             Borenstein/Rose  Mail-Enabled Applications           Page 11
  627.  
  628.  
  629.  
  630.  
  631.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [12]
  632.  
  633.  
  634.                  SafeTcl_getmessage -- "SafeTcl_getmessage  start  len".
  635.                       This  function  returns a string containing all or
  636.                       part of the entire message, including the  message
  637.                       headers.   The  start parameter tells where in the
  638.                       message to the string should start, where 0 is the
  639.                       first  octet.   The  len  parameter tells how many
  640.                       octets of the message to return,  where  -1  means
  641.                       the whole message.  Thus "SafeTcl_getmessage 0 -1"
  642.                       will  return  the   entire   message,   but   more
  643.                       sophisticated  approaches  can  be  used  to avoid
  644.                       allocated a Tcl string  for,  say,  a  2  gigabyte
  645.                       video clip.
  646.  
  647.             4.5.  Additional Activation-Time Functionality
  648.  
  649.             When a Safe-Tcl program is received in a mail  message  with
  650.             the  evaluation-time  parameter  given  as "activation", the
  651.             mail message  is  intended  to  be  run  in  an  interactive
  652.             setting,  with  the  ability  to  interact  with  the  user.
  653.             Several additional Safe-Tcl procedures may become  available
  654.             in this context, some of which are only available in certain
  655.             user interface contexts.
  656.  
  657.             In a non-mail Safe-Tcl  application,  these  primitives  may
  658.             also be present if and only if there is a user with whom the
  659.             program can interact.
  660.  
  661.             4.5.1.  User Interaction Models:  SafeTcl_InterfaceStyle
  662.  
  663.             Second only to safety as a  critical  issue  for  an  active
  664.             messaging   language  is  the  question  of  user  interface
  665.             capabilities.  Since the language needs to be able  to  work
  666.             in  a wide variety of hardware and software environments, it
  667.             is difficult to avoid a  "lowest  common  denominator"  user
  668.             interface.   Safe-Tcl  addresses this problem by providing a
  669.             few  lowest  common  denominator  primitives,  and  then  by
  670.             providing  a  mechanism  by  which the availability of well-
  671.             defined packages of more advanced user interface  mechanisms
  672.             can be made known to a Safe-Tcl program at runtime.
  673.  
  674.             In  particular,  it  is   specified   that   each   Safe-Tcl
  675.             interpreter     must     provide    a    global    variable,
  676.             SafeTcl_InterfaceStyle, which indicates any  user  interface
  677.             extensions   that  are  available.   If  no  user  interface
  678.             extensions are available, the variable should be set to  the
  679.             one-element  list  "{generic}"  to  indicate  that  only the
  680.  
  681.  
  682.  
  683.             Borenstein/Rose  Mail-Enabled Applications           Page 12
  684.  
  685.  
  686.  
  687.  
  688.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [13]
  689.  
  690.  
  691.             generic "lowest common denominator" functions are available.
  692.  
  693.             In order to permit future Safe-Tcl interpreters to implement
  694.             multiple   user   interface   extensions,   the   value   of
  695.             SafeTcl_InterfaceStyle may be a Tcl list of  supported  user
  696.             interface   extensions.   Thus  if  a  Safe-Tcl  interpreter
  697.             supported  both  the  "foo"   and   "bar"   user   interface
  698.             extensions, it would set SafeTcl_InterfaceStyle to {foo bar}
  699.             or {bar foo}.  (The support for  the  generic  functions  is
  700.             always  required,  and  therefore  need  not  be declared in
  701.             SafeTcl_InterfaceStyle.    However,   it   would   also   be
  702.             legitimate  to  set  this  value  to  {foo bar generic}, for
  703.             example.)
  704.  
  705.             The string or strings in the  SafeTcl_InterfaceStyle  should
  706.             all be interpreted in a case-insensitive manner.
  707.  
  708.             It is expected that a common approach  to  writing  Safe-Tcl
  709.             programs  will  be  to  include  multiple  versions  of user
  710.             interface functions, as in  the  following  pseudo-Safe-Tcl-
  711.             code
  712.  
  713.                  if {[lsearch $SafeTcl_InterfaceStyle "Tk3.2"]} {
  714.                      do_Tk_style_interaction
  715.                  } else {
  716.                      do_generic_style_interaction
  717.                  }
  718.  
  719.             It is expected that gradually many such constructs  will  be
  720.             abstracted  and  hidden behind reusable "portable" procedure
  721.             definitions (e.g. an "AskMultipleChoice" procedure), but the
  722.             SafeTcl_InterfaceStyle   mechanism   will   permit  Safe-Tcl
  723.             program  authors  access  to  more  general  user  interface
  724.             mechanisms  than  if  they  were  limited  to  such portable
  725.             procedures, as in [ATOMICMAIL].
  726.  
  727.             4.5.2.  Generic User Interaction
  728.  
  729.             The following user interaction primitives are  available  in
  730.             the  "generic"  interface  style, and hence are available to
  731.             all interactive Safe-Tcl programs.
  732.  
  733.                  SafeTcl_displaytext -- "SafeTcl_displaytext txt".  This
  734.                       primitive simply shows the given text to the user.
  735.                       The string specified may be of  arbitrary  length,
  736.                       so  consideration  must  be  given to scrolling or
  737.  
  738.  
  739.  
  740.             Borenstein/Rose  Mail-Enabled Applications           Page 13
  741.  
  742.  
  743.  
  744.  
  745.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [14]
  746.  
  747.  
  748.                       pagination as necessary.  Zero is always returned;
  749.                       an  error  is generated if the string could not be
  750.                       displayed.
  751.  
  752.                  SafeTcl_displayline  --    "SafeTcl_displayline   txt".
  753.                       This  primitive simply shows the given text to the
  754.                       user.  The string specified is a  single  line  of
  755.                       text.   Zero  is  always  returned;  an  error  is
  756.                       generated if the string could not be displayed.
  757.  
  758.                  SafeTcl_gettext --  "SafeTcl_gettext prompt ?default?".
  759.                       This  primitive  obtains an arbitrary body of text
  760.                       from the user, which is returned as a Tcl  string.
  761.                       The  first  argument is used as a prompting string
  762.                       to solicit the  text  from  the  user,  while  the
  763.                       optional  second  argument  is  the  default to be
  764.                       offered.  An error  is  generated  if  the  string
  765.                       cannot be obtained.
  766.  
  767.                  SafeTcl_getline --  "SafeTcl_getline prompt ?default?".
  768.                       This  primitive obtains a single line of text from
  769.                       the user, which is returned as a Tcl string.   The
  770.                       first  argument  is  used as a prompting string to
  771.                       solicit the text from the user, while the optional
  772.                       second  argument is the default to be offered.  An
  773.                       error  is  generated  if  the  string  cannot   be
  774.                       obtained.
  775.  
  776.                  SafeTcl_displayentity -- "SafeTcl_displayentity  entity
  777.                       ?body?".    This   causes  a  MIME  entity  to  be
  778.                       displayed to the user.  The "entity" string may be
  779.                       one    of   the   numeric   values   returned   by
  780.                       SafeTcl_getparts, or (if it begins  with  "<"  and
  781.                       ends  with  ">")  it  may  be  a  Content-ID value
  782.                       identifying the MIME entity.  The manner in  which
  783.                       the entity is displayed, and the set of MIME types
  784.                       that are supported,  is  implementation-dependent.
  785.                       SafeTcl_displayentity  returns 0 if the entity was
  786.                       displayed to the user, and generates an  error  if
  787.                       for any reason it was not.
  788.  
  789.             Note   that   the   five   primitives   SafeTcl_displaytext,
  790.             SafeTcl_displayline,  SafeTcl_gettext,  SafeTcl_getline, and
  791.             SafeTcl_displayentity, constitute the entire "generic"  user
  792.             interface  of  the  core Safe-Tcl language.  Additional user
  793.             interface capabilities may be indicated  using  the  always-
  794.  
  795.  
  796.  
  797.             Borenstein/Rose  Mail-Enabled Applications           Page 14
  798.  
  799.  
  800.  
  801.  
  802.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [15]
  803.  
  804.  
  805.             present global variable SafeTcl_InterfaceStyle, as described
  806.             above. However, these five primitives are guaranteed  to  be
  807.             available for every Safe-Tcl implementation, and can be used
  808.             either to write "lowest common denominator" user  interfaces
  809.             or   to   provide   a   backup    user  interface  when  the
  810.             SafeTcl_InterfaceStyle variable indicates that no recognized
  811.             user interface extensions are available.
  812.  
  813.             4.5.3.  X11 Interaction: Interface Style Tk3.2
  814.  
  815.             This document defines the use of  a  single  user  interface
  816.             extension  set, corresponding to a large subset of Tk, the X
  817.             Window System extensions for Tcl.  The availability of  this
  818.             user  interface  capability  is declared by the inclusion of
  819.             the string "Tk3.2" in the  SafeTcl_InterfaceStyle  variable.
  820.             The  choice  of  "3.2" is indicative of the fact that the Tk
  821.             primitives described here are derived from Tk  version  3.2.
  822.             However, this should NOT be taken to indicate that arbitrary
  823.             other versions of Tk may be used with a corresponding change
  824.             to  the  SafeTcl_InterfaceStyle string.  If a future version
  825.             of the Tk interface style for Safe-Tcl is ever  defined,  it
  826.             will be formally specified and published as part of the MIME
  827.             process.  It is  explicitly  NOT  the  case  that  arbitrary
  828.             versions  of  Tk  may  be  used  with  a  suitably  modified
  829.             InterfaceStyle value.
  830.  
  831.             As with the core Safe-Tcl language, the Tk  extensions  will
  832.             be described in terms of differences from the standard Tk3.2
  833.             language.  Since Tk does not extend the basic syntax of  the
  834.             language,  all  that  neds  to  be  specified  is the set of
  835.             available primitives.
  836.  
  837.             Only one Tk primitive is omitted from Safe-Tcl,  namely  the
  838.             "send" primitive.
  839.  
  840.             All of the  other  core  Tk  procedures  and  functions  are
  841.             retained. In particular, the COMPLETE set of functions to be
  842.             define by the "Tk3.2" interface style  for  Safe-Tcl  is  as
  843.             follows:
  844.  
  845.                  after, bind, button, canvas, checkbutton, destroy,
  846.                  entry, focus, frame, grab, label, lineto, listbox,
  847.                  menu, menubutton, message, moveto,  option,  pack,
  848.                  place,  radiobutton,  scale, scrollbar, selection,
  849.                  text,   tk,   tk_bindForTraversal,   tk_firstMenu,
  850.                  tk_getMenuButtons, tk_invokeMenu, tk_mbButtonDown,
  851.  
  852.  
  853.  
  854.             Borenstein/Rose  Mail-Enabled Applications           Page 15
  855.  
  856.  
  857.  
  858.  
  859.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [16]
  860.  
  861.  
  862.                  tk_mbPost,  tk_mbUnpost,   tk_menuBar,   tk_menus,
  863.                  tk_nextMenu,  tk_nextMenuEntry, tk_traverseToMenu,
  864.                  tk_traverseWithinMenu, tkwait,  toplevel,  update,
  865.                  winfo, wm
  866.  
  867.             5.  Extensions to the Safe-Tcl Environment
  868.  
  869.             All Safe-Tcl extensions are handled  by  a  single  Safe-Tcl
  870.             procedure, SafeTcl_untrusted_eval:
  871.  
  872.                  SafeTcl_untrusted_eval    --    "SafeTcl_untrusted_eval
  873.                       command  arguments...".   This command may be used
  874.                       by a Safe-Tcl  program  to  communicate  with  the
  875.                       TRUSTED  Tcl  interpreter  in  the  same  process.
  876.                       SafeTcl_untrusted_eval makes all substitutions and
  877.                       evaluates  all  of  the arguments in the untrusted
  878.                       environment.  It then passes its arguments  on  to
  879.                       the  procedure  "untrusted_eval"  in  the  trusted
  880.                       interpreter.     The     trusted     interpreter's
  881.                       untrusted_eval  procedure  will decide whether not
  882.                       the  given  command  and  arguments  are  safe  to
  883.                       evaluate, and, if they ar deemed safe, will return
  884.                       the result of the evaluation, and  will  otherwise
  885.                       generate  an  error.  The untrusted_eval procedure
  886.                       will    always    set    the    global    variable
  887.                       SafeTcl_downgraded_cmd     in     the    untrusted
  888.                       interpeter.  Normally, it will set it to the empty
  889.                       string,  but  in  the  event  that  an  error  was
  890.                       generated because the command was  deemed  unsafe,
  891.                       but  there  is  a "downgraded" version of the same
  892.                       command  that  would  be  considered  safe,   this
  893.                       command      will     be     placed     in     the
  894.                       SafeTcl_downgraded_cmd   variable.    A   safe-tcl
  895.                       program could thus use the Tcl "catch" facility to
  896.                       catch errors and execute the downgraded command if
  897.                       desired.
  898.  
  899.             The actual decision about what can and cannot  be  evaluated
  900.             by  SafeTcl_untrusted_eval  is  made  by  the untrusted_eval
  901.             procedure in the trusted interpreter, which is discussed  in
  902.             the following section.
  903.  
  904.             This mehanism makes possible a wide variety of extensions to
  905.             SafeTcl.   For  example, the core Safe-Tcl language does not
  906.             include a library mechanism, but a library  mechanism  could
  907.             be   implemented   with   the   careful   extension  of  the
  908.  
  909.  
  910.  
  911.             Borenstein/Rose  Mail-Enabled Applications           Page 16
  912.  
  913.  
  914.  
  915.  
  916.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [17]
  917.  
  918.  
  919.             untrusted_eval mechanism.
  920.  
  921.             6.  Recommended Extensions to the Trusted  Tcl Interpeter
  922.  
  923.             In order to  permit  the  core  Safe-Tcl  language  to  have
  924.             extensibility  and  minimal  support  to sending message and
  925.             generating  paper  output,  it  is  necessary  that  certain
  926.             procedures  be  added to the trusted interpreter.  Note that
  927.             these  commands  should  NOT  be  added  to   the   Safe-Tcl
  928.             interpreter,  as  this  would  not be considered safe.  (One
  929.             could imagine a mail message  that  automatically  generates
  930.             hate  mail  in  the  recipient's  name,  or  a  message that
  931.             maliciously  wastes  printer  resources   or   sabotages   a
  932.             programmable printer.)
  933.  
  934.             The following procedures should be included in  the  TRUSTED
  935.             Tcl  interpreter that is accessible to Safe-Tcl programs via
  936.             the extension mechanisms previously described:
  937.  
  938.                  MIME_sendmessage --  "MIME_sendmessage  -to  <addrlist>
  939.                       -subject  <string>  -body  <body>  -cc  <addrlist>
  940.                       -auxheader <name> <value>".  This command  may  be
  941.                       used to send a message. It takes a variable number
  942.                       of  key/value  arguments,  three  of   which   are
  943.                       required.   The required "-to <addrlist>" argument
  944.                       specifies  a  string  containing   one   or   more
  945.                       electronic  mail  addresses  in  Internet-standard
  946.                       (RFC 822)  format  (e.g.  with  commas  separating
  947.                       multiple   addresses).   The   required  "-subject
  948.                       <string>" argument specifies the  subject  of  the
  949.                       mail  being  sent.   The  required  "-body <body>"
  950.                       argument specifies the mail  body,  which  is  the
  951.                       value  returned  by  a SafeTcl_makebody call.  The
  952.                       optional "-cc <addrlist>" argument specifies a  CC
  953.                       address  list,  in  the  same  format  as  the -to
  954.                       addrlist.   Finally,  the   optional   "-auxheader
  955.                       <name> <value> argument, which may appear multiple
  956.                       times  in  a  single  call  to   MIME_sendmessage,
  957.                       specifies auxilliary headers which may be added to
  958.                       the  mail  message.   For   example,   "-auxheader
  959.                       Reply-to:   bgates@microsoft.com"   will  cause  a
  960.                       header line "Reply-to: bgates@microsoft.com" to be
  961.                       added  to  the  message.   MIME_sendmessage should
  962.                       return 0 on successful mail delivery, and generate
  963.                       an  error  if  the  mail  cannot  be  sent.  It is
  964.                            acceptable,  but  not  m  andatory,  in   the
  965.  
  966.  
  967.  
  968.             Borenstein/Rose  Mail-Enabled Applications           Page 17
  969.  
  970.  
  971.  
  972.  
  973.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [18]
  974.  
  975.  
  976.                       "activation"  evaluation-time or other interactive
  977.                       contexts, to offer the  user  the  opportunity  to
  978.                       edit such mail before it is delivered.
  979.  
  980.                  MIME_printtext -- "MIME_printtext txt".   This  command
  981.                       may  be  used  to  send  plain  textual  data to a
  982.                       locally-available printer.  It takes one argument,
  983.                       the  text  to  be  printed.  MIME_printtext should
  984.                       return 0 on successful  submission  of  the  print
  985.                       job,  and generate an error if the material cannot
  986.                       be printed.
  987.  
  988.                  untrusted_eval   --   "untrusted_eval   evaluation-time
  989.                       command  arguments...".  This procedure is invoked
  990.                       in  the  TRUSTED  Tcl  interpreter  whenever   the
  991.                       SafeTcl  interpreter in the same process evaluates
  992.                       the SafeTcl_untrusted_eval command.   Before  this
  993.                       invocation,   SafeTcl_untrusted_eval   makes   all
  994.                       substitutions and evaluates all of  the  arguments
  995.                       in  the  untrusted  environment,  and  adds in the
  996.                       evaluation-time parameter based on the context  in
  997.                       which  the  Safe-Tcl  program  is  being evaluated
  998.                       (either "activation" or "delivery").   Other  than
  999.                       evaluation-time, the parameters for untrusted_eval
  1000.                       are the same as for SafeTcl_untrusted_eval  except
  1001.                       that   all   substitutions  and  evaluations  have
  1002.                       already been  performed.   The  implementation  of
  1003.                       untrusted_eval  is  the key both to all extensions
  1004.                       of Safe-Tcl and to the  integrity  of  the  safety
  1005.                       mechanisms   designed   into   Safe-Tcl,   and  is
  1006.                       discussed in detail in Appendix D.
  1007.  
  1008.                  eval_in_safetcl  --  "eval_in_safetcl  program".   This
  1009.                       command  evaluates  the  given  Tcl program in the
  1010.                       untrusted environment.  This gives code written in
  1011.                       the   trusted   environment  --  and  particularly
  1012.                       implementations and extensions  to  untrusted_eval
  1013.                       --  access  to  the current state of the untrusted
  1014.                       interpreter.
  1015.  
  1016.                  MIME_savemsg  -- "savemsg type ?destination?".     This
  1017.                       command appends the message to either a mailbox or
  1018.                       a folder, as specified  by  the  first  parameter,
  1019.                       which  should be either "mailbox" or "folder".  If
  1020.                       the second  parameter is  the  empty  string,  the
  1021.                       recipient's  default  mailbox  or  folder is used.
  1022.  
  1023.  
  1024.  
  1025.             Borenstein/Rose  Mail-Enabled Applications           Page 18
  1026.  
  1027.  
  1028.  
  1029.  
  1030.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [19]
  1031.  
  1032.  
  1033.                       Note that the behavior of  this  command  will  be
  1034.                       highly  implementation-dependent,  and may also be
  1035.                       user-customizable to deal with  different  mailbox
  1036.                       and folder formats.
  1037.  
  1038.             7.  Notes To Implementors
  1039.  
  1040.             Implementation details are  usually  considered  beyond  the
  1041.             scope  of  a  specification  such as this one.  However, the
  1042.             extremely sensitive nature of a  Safe-Tcl  interpreter,  and
  1043.             the  safety issues entailed in the implementation of such an
  1044.             interpreter,  suggests  that  some  advice  to  implementors
  1045.             might be useful here.
  1046.  
  1047.             1.  Be careful how you implement  any  user  interface  code
  1048.             that asks for confirmation of potentially dangerous actions,
  1049.             e.g. in MIME_sendmessage or MIME_printtext.  In  particular,
  1050.             such   code   should   always  be  written  in  the  trusted
  1051.             interpreter,  to  prevent  hostile  programs  from  "reverse
  1052.             engineering"  your  implementation  and short-circuiting the
  1053.             confirmation code.    (A  more  radical  alternative  is  to
  1054.             prohibit  the  use  of  the Tcl primitives proc or rename to
  1055.             redefine any built-in Safe-Tcl  primtives  or  any  Safe-Tcl
  1056.             procedures defiined for the confirmation process itself.)
  1057.  
  1058.             2.  A Safe-Tcl  interpreter  should  ensure  that  there  is
  1059.             ALWAYS  some  indication  on  the  screen  that an untrusted
  1060.             program is being run.  A suggested mechanism is to  reserve,
  1061.             as  a  "status line" the top or bottom line of each terminal
  1062.             or window in which Safe-Tcl is running.   That  line  should
  1063.             indicate  that  the  program  is  not  to  be  trusted  with
  1064.             sensitive information.  This will help to prevent  a  clever
  1065.             Safe-Tcl  program  from  fooling  the  user into supplying a
  1066.             password, e.g. by spoofing a login program.
  1067.  
  1068.             3.  A Safe-Tcl interpreter that  runs  on  a  video  display
  1069.             terminal  or terminal emulator should beware of permitting a
  1070.             Safe-Tcl program to send escape codes to the terminal.  Some
  1071.             terminals  can  be programmed, using binary escape codes, to
  1072.             send data to the terminal which is then  sent  back  to  the
  1073.             host  computer,  and  might  be  used  to "break out" of the
  1074.             Safe-Tcl environment.  Safe-Tcl  interpreters  that  run  on
  1075.             such   terminals   might   wish  to  render  into  printable
  1076.             characters all lines that are displayed with such primitives
  1077.             as   SafeTcl_displaytext   and   SafeTcl_displayline,   thus
  1078.             inhibiting the transmission  of  raw  escape  codes  to  the
  1079.  
  1080.  
  1081.  
  1082.             Borenstein/Rose  Mail-Enabled Applications           Page 19
  1083.  
  1084.  
  1085.  
  1086.  
  1087.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [20]
  1088.  
  1089.  
  1090.             terminal.
  1091.  
  1092.             4.   Special  care  must  be  paid   to   all   aspects   of
  1093.             untrusted_eval, as discussed in appendix D.
  1094.  
  1095.             Security Considerations
  1096.  
  1097.             Active messaging, in which programs  are  sent  through  the
  1098.             mail  to be evaluated automatically or semi-automatically on
  1099.             behalf of the recipient, is an area fraught  with  potential
  1100.             security  problems.   Accordingly, the most important aspect
  1101.             of the design of the application/Safe-Tcl MIME type was  the
  1102.             care  that was paid to defining an active messaging language
  1103.             that was capable of safe implementation.
  1104.  
  1105.             Despite this care, there remain two potential pitfalls  that
  1106.             could  cause  the  application/Safe-Tcl  type  to  become  a
  1107.             vehicle for security  problems,  and  all  implementors  and
  1108.             administrators should be aware of these problems:
  1109.  
  1110.             1.  Implementation bugs.  No matter how much care is paid to
  1111.             the  design of a language for active messaging, interpreters
  1112.             of such a language will remain as  vulnerable  to  security-
  1113.             compromising bugs as any other network services. Just as the
  1114.             Internet worm was able to exploit bugs  in  the  finger  and
  1115.             sendmail  programs,  so  too  bugs in a Safe-Tcl interpreter
  1116.             might be exploited by future  sociopaths.    This  does  not
  1117.             argue  against  the  concept  of Safe-Tcl, but suggests that
  1118.             system administrators must be  clear  about  the  difference
  1119.             between  a  safe  language and a correct implementation of a
  1120.             safe  language,  and  should  INSTALL  ONLY  THOSE  SAFE-TCL
  1121.             INTERPRETERS THAT COME FROM EXTREMELY TRUSTED SOURCES.
  1122.  
  1123.             2.  Poorly-conceived extensions or supersets.  Safe-Tcl  is,
  1124.             by design, a highly restricted language.  It is very easy to
  1125.             add extensions that will make it  more  powerful,  but  such
  1126.             extensions  can  easily  have  the effect of undoing all the
  1127.             security-consciousness that went into the original design of
  1128.             the   language.   (Such  extensions  won't  exactly  promote
  1129.             interoperability,  either,  another  good  reason  to  avoid
  1130.             them.)   Administrators should beware of installing software
  1131.             that claims to implement a  superset  of  Safe-Tcl,  as  the
  1132.             basic  Tcl  language  is not itself safe for sending through
  1133.             the mail.  Users and administrators alike must exercise care
  1134.             in  the  use  of the Safe-Tcl extension mechanisms.  When in
  1135.             doubt, simply don't install an extension to Safe-Tcl.
  1136.  
  1137.  
  1138.  
  1139.             Borenstein/Rose  Mail-Enabled Applications           Page 20
  1140.  
  1141.  
  1142.  
  1143.  
  1144.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [21]
  1145.  
  1146.  
  1147.             Authors' Addresses
  1148.  
  1149.             For more information, the author of  this  document  may  be
  1150.             contacted via Internet mail:
  1151.  
  1152.                                 Nathaniel S. Borenstein
  1153.                                  MRE 2D-296, Bellcore
  1154.                                      445 South St.
  1155.                                Morristown, NJ 07962-1910
  1156.                                          US
  1157.  
  1158.                                 Phone: +1 201 829 4270
  1159.                                  Fax:  +1 201 829 5963
  1160.                                 Email: nsb@bellcore.com
  1161.  
  1162.                                   Marshall T. Rose
  1163.                             Dover Beach Consulting, Inc.
  1164.                                  420 Whisman Court
  1165.                            Mountain View, CA  94043-2186
  1166.                                          US
  1167.  
  1168.                                Phone: +1 415 968 1052
  1169.                                Fax:   +1 415 968 2510
  1170.                            Email: mrose@dbc.mtview.ca.us
  1171.             Acknowledgements
  1172.  
  1173.             This  document  reflects  the  input  and  ideas   of   many
  1174.             researchers  and  developers who have worked in the field of
  1175.             active messaging over the last  two  decades.   Particularly
  1176.             helpful  in  the  drafting  of  this document have been Dave
  1177.             Crocker, Karl Lehenbauer, John Ousterhout,  Rich  Salz,  and
  1178.             Allan Shepherd.
  1179.  
  1180.             Special thanks are due to John Ousterhout,  for  the  design
  1181.             and implementation of Tcl and Tk.
  1182.  
  1183.             References
  1184.  
  1185.             [RFC-MIME]   Borenstein,   N.,   and   N.   Freed,     "MIME
  1186.             (Multipurpose    Internet   Mail   Extensions)   Part   One:
  1187.             Mechanisms for  Specifying  and  Describing  the  Format  of
  1188.             Internet Message Bodies", RFC 1341, June, 1992.
  1189.  
  1190.             [ATOMICMAIL] Borenstein, Nathaniel S.,  "Computational  Mail
  1191.             as Network Infrastructure for Computer-Supported Cooperative
  1192.             Work", in  Proceedings  of  CSCW  '92  Conference,  Toronto,
  1193.  
  1194.  
  1195.  
  1196.             Borenstein/Rose  Mail-Enabled Applications           Page 21
  1197.  
  1198.  
  1199.  
  1200.  
  1201.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [22]
  1202.  
  1203.  
  1204.             Ontario, November, 1992.
  1205.  
  1206.             [TCL]   Ousterhout, John,  An Introduction to  Tcl  and  Tk.
  1207.             Addison-Wesley, 1993 (to appear).
  1208.  
  1209.             [EM-MODEL]     Rose, M., and N.  Borenstein,  "A  Model  for
  1210.             Enabled Mail (EM)", draft in preparation, May, 1993.
  1211.  
  1212.             Appendix A: Examples
  1213.  
  1214.             A. 1. Usage Example: Delivery-Time Enabled Mail
  1215.  
  1216.             Here is a brief example of a program that might be evaluated
  1217.             during the delivery evaluation-time.
  1218.  
  1219.                  Content-Type: application/safe-tcl;
  1220.                        evaluation-time=delivery
  1221.  
  1222.                  SafeTcl_untrusted_eval \
  1223.                  MIME_sendmessage \
  1224.                       -to $SafeTcl_originator \
  1225.                       -subject "Delivery Notification for
  1226.                  $SafeTcl_recipient" \
  1227.                       -body [SafeTcl_makebody "text/plain" \
  1228.                            [SafeTcl_getheader "Message-ID"]]
  1229.  
  1230.  
  1231.             This simply sends a message  to  the  originator  indicating
  1232.             that  the incoming message crossed the delivery slot for the
  1233.             recipient.
  1234.  
  1235.             A. 2. Usage Example:  Activation-Time Enabled Mail
  1236.  
  1237.             Here is a brief example of a program that might be evaluated
  1238.             during the activation evalution-time.
  1239.  
  1240.                  Content-Type: application/safe-tcl;
  1241.                        evaluation-time=activation
  1242.  
  1243.                  proc ordershirt {} {
  1244.                      SafeTcl_untrusted_eval \
  1245.                          MIME_sendmessage  -to tshirts@whitehouse.gov \
  1246.                              -subject "Shirt request" \
  1247.                              -body [SafeTcl_makebody "text/plain" \
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.             Borenstein/Rose  Mail-Enabled Applications           Page 22
  1254.  
  1255.  
  1256.  
  1257.  
  1258.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [23]
  1259.  
  1260.  
  1261.                                           [SafeTcl_getline \
  1262.                                                "What size t-shirt do you
  1263.                  wear?" \
  1264.                                                "medium"]]
  1265.                      exit
  1266.                  }
  1267.  
  1268.                  global SafeTcl_InterfaceStyle
  1269.                  if {[lsearch $SafeTcl_InterfaceStyle "Tk3.2"] >= 0} {
  1270.                      message .m -aspect 1000 \
  1271.                       -text "Click below if you want a free Bill Clinton
  1272.                  t-shirt!"
  1273.                      button .b -text "Click here for free shirt!" \
  1274.                          -command ordershirt
  1275.                      button .b2 -text "Click here to exit without
  1276.                  ordering" \
  1277.                           -command exit
  1278.                      pack append . .m {pady 20} .b {pady 20} .b2 {pady
  1279.                  20}
  1280.                  } else {
  1281.                      set ans [string index \
  1282.                                       [SafeTcl_getline  \
  1283.                                       "Do you want a free Clinton t-
  1284.                  shirt? "  \
  1285.                                       "No"] \
  1286.                                     0]
  1287.                      if {$ans == "y" || $ans == "Y"} {
  1288.                          ordershirt
  1289.                      }
  1290.                      exit
  1291.                  }
  1292.  
  1293.             The above program (which will use the Tk3.2 interface  style
  1294.             if  it  is  available,  and  will  otherwise use the default
  1295.             style) will offer the user the opportunity to order  a  free
  1296.             t-shirt.
  1297.  
  1298.             Appendix B: Summary of Safe-Tcl Primitives
  1299.  
  1300.             **** Need to make a table, with domains of applicability for
  1301.             each.
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.             Borenstein/Rose  Mail-Enabled Applications           Page 23
  1311.  
  1312.  
  1313.  
  1314.  
  1315.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [24]
  1316.  
  1317.  
  1318.             Appendix C: User-Friendly Renderings
  1319.  
  1320.             When  displaying  an  RFC  822  address,   a   user-friendly
  1321.             rendering may be preferred.  In practice, an RFC 822 address
  1322.             usually appears in one of these two forms:
  1323.  
  1324.                  phrase (comment) <local@domain>
  1325.                  local@domain (comment)
  1326.  
  1327.             Although the algorithm for generating such  a  rendering  is
  1328.             implementation specific, the following is recommended.
  1329.  
  1330.                  1. if a phrase is present, return  that  as  the  user-
  1331.                       friendly rendering; otherwise,
  1332.  
  1333.                  2. if at least one comment is present, take  the  first
  1334.                       one,  remove  the  parenthesis, and return that as
  1335.                       the user-friendly rendering; otherwise,
  1336.  
  1337.                  3. if the local-part does not  appears  to  be  in  the
  1338.                       syntax  defined by RFC 1327 (e.g., a collection of
  1339.                       /key=value/ strings), then return  the  local-part
  1340.                       as the user-friendly rendering; otherwise,
  1341.  
  1342.                  4. if a string of the form
  1343.  
  1344.                       /PN=value/
  1345.  
  1346.                       is present in the  local-part,  then  replace  any
  1347.                       dots in "value" with spaces and return that as the
  1348.                       user-friendly rendering; otherwise,
  1349.  
  1350.                  5. if a string of the form
  1351.  
  1352.                       /S=value/
  1353.  
  1354.                       is not present, then return the local-part as  the
  1355.                       user-friendly rendering; otherwise,
  1356.  
  1357.                  6. if a string of the form
  1358.  
  1359.                       /G=value/
  1360.  
  1361.                       is present , then return "G-value S-value" as  the
  1362.                       user-friendly rendering; otherwise,
  1363.  
  1364.  
  1365.  
  1366.  
  1367.             Borenstein/Rose  Mail-Enabled Applications           Page 24
  1368.  
  1369.  
  1370.  
  1371.  
  1372.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [25]
  1373.  
  1374.  
  1375.                  7. return "S-value" as the user-friendly rendering.
  1376.  
  1377.             Appendix D:   Recommendations Regarding untrusted_eval
  1378.  
  1379.             The simplest possible implementation of untrusted_eval would
  1380.             be  to  simply  evaluate  the  given  command with the given
  1381.             arguments.  This would be simple, but would also open up  an
  1382.             enormous security hole, effetively granting each mail reader
  1383.             complete computational access  to  the  environment  of  the
  1384.             recipient.    This  is  not  considered acceptable under any
  1385.             circumstances.
  1386.  
  1387.             The safest possible implementation of untrusted_eval  is  to
  1388.             always return an error. Unfortunately, this denies access to
  1389.             some functionality that is expected to be vital to  Safe-Tcl
  1390.             programs.
  1391.  
  1392.             Therefore this appendix specifies, in  algorithmic  form,  a
  1393.             recommended   minimal   implementation   of  untrusted_eval.
  1394.             Implementors,  administrators,  and  users  alike  are   all
  1395.             cautioned   to   think  long  and  hard  about  any  further
  1396.             extensions they make to untrusted_eval.  It should always be
  1397.             borne  in  mind  that  this code might be evaluated for mail
  1398.             sent by hostile  senders,  running  with  the  identity  and
  1399.             privileges  of  unwary  recipients.   In  particular, NETHER
  1400.             untrusted_eval NOR ANY PROCEDURE CALLED BY  IT  SHOULD  EVER
  1401.             EVAUATE ITS ARGUMENTS AS TCL EXPRESSIONS OR PROGRAMS.
  1402.  
  1403.             What  follows  is  a  recommended  default   algorithm   for
  1404.             untrusted_eval.
  1405.  
  1406.  
  1407.             SET SafeTcl_downgraded_cmd to ""
  1408.             IF (command == "MIME_sendmessage") then
  1409.                IF (evaluation-time == "delivery") then
  1410.                   IF (to-and-cc-names == Tcl_Originator) then
  1411.                      EXECUTE-COMMAND
  1412.                   else
  1413.                      SET SafeTcl_downgraded_cmd to be the
  1414.                         original command with the
  1415.                        -to argument set to Tcl_Originator
  1416.                        and -cc argument set to ""
  1417.                      GENERATE-ERROR
  1418.                   endif
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.             Borenstein/Rose  Mail-Enabled Applications           Page 25
  1425.  
  1426.  
  1427.  
  1428.  
  1429.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [26]
  1430.  
  1431.  
  1432.                else
  1433.                   if (User inspects mail and OK's it) then
  1434.                      EXECUTE-COMMAND
  1435.                   else
  1436.                      GENERATE-ERROR
  1437.                   endif
  1438.                endif
  1439.             else IF (command == "MIME_printtext") then
  1440.                IF (evaluation-time == "delivery") then
  1441.                   GENERATE-ERROR
  1442.                else
  1443.                   if (User inspects text and OK's it) then
  1444.                      EXECUTE-COMMAND
  1445.                   else
  1446.                      GENERATE-ERROR
  1447.                   endif
  1448.                endif
  1449.             else
  1450.                GENERATE-ERROR
  1451.             endif
  1452.  
  1453.             In other words, at activation time,  the  user  is  given  a
  1454.             chance to  OK  sending mail or printing information, but all
  1455.             other actions are  rejected.   At  delivery  time  the  only
  1456.             action   accepted  by  untrusted_eval  is  sending  mail  to
  1457.             Tcl_Originator only.
  1458.  
  1459.             Because the envelope information on which Tcl_Originator  is
  1460.             based  may  be  forged,  it  is further recommended that, at
  1461.             delivery time, any mail which is sent by this  mechanism  to
  1462.             Tcl_Originator  should  be  sent with a "From:" address that
  1463.             clearly indicates that the reply was sent  by  an  automatic
  1464.             agent,   rather  than  a  human  being.   Thus,  instead  of
  1465.             generating mail with
  1466.  
  1467.                  From: Nathaniel Borenstein <nsb@bellcore.com>
  1468.  
  1469.             the mail should be generated with a From field such as
  1470.  
  1471.                  From: Mail Delivery Agent for Nathaniel Borenstein
  1472.                       <nsb@bellcore.com>
  1473.  
  1474.             Note also that it is better to put this information  in  the
  1475.             RFC  822  phrase  than  in a comment, since comments in mail
  1476.             addresses are sometimes discarded.
  1477.  
  1478.  
  1479.  
  1480.  
  1481.             Borenstein/Rose  Mail-Enabled Applications           Page 26
  1482.  
  1483.  
  1484.  
  1485.  
  1486.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [27]
  1487.  
  1488.  
  1489.             It  is  also  prudent  for  implementations  to   save   the
  1490.             delivery-time  Safe-Tcl messages that generate such mail for
  1491.             a few days, to be used for investigations into abuses of the
  1492.             facility.
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.             Borenstein/Rose  Mail-Enabled Applications           Page 27
  1539.  
  1540.  
  1541.  
  1542.  
  1543.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [28]
  1544.  
  1545.  
  1546.  
  1547.                            Things To Do Before Publishing
  1548.  
  1549.  
  1550.  
  1551.             -- Specify at least one encryption algorithm to use  (enlist
  1552.             Peter Winkler?)
  1553.  
  1554.             -- Flesh out appendix B
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.             Borenstein/Rose  Mail-Enabled Applications           Page 28
  1596.  
  1597.  
  1598.  
  1599.  
  1600.             Borenstein/Rose  Mail-Enabled Applications     May 1993 [29]
  1601.  
  1602.  
  1603.  
  1604.  
  1605.                                Table of Contents
  1606.  
  1607.  
  1608.             1.  Overview.............................................  1
  1609.             2.  The application/Safe-Tcl content-type................  2
  1610.             3.  The multipart/enabled-mail content-type..............  3
  1611.             4.  The Safe-Tcl Language................................  4
  1612.             4.1.  The Core Safe-Tcl Language.........................  4
  1613.             4.2.  Universal Safe-Tcl Functionality...................  5
  1614.             4.3.  Additional Messaging Functionality.................  7
  1615.             4.4.  Additional Delivery-Time Functionality............. 11
  1616.             4.5.  Additional Activation-Time Functionality........... 12
  1617.             4.5.1.  User Interaction Models:  SafeTcl_InterfaceStyle. 12
  1618.             4.5.2.  Generic User Interaction......................... 13
  1619.             4.5.3.  X11 Interaction: Interface Style Tk3.2........... 15
  1620.             5.  Extensions to the Safe-Tcl Environment............... 16
  1621.             6.  Recommended Extensions to the Trusted Tcl Interpeter. 17
  1622.             7.  Notes To Implementors................................ 19
  1623.             Security Considerations.................................. 20
  1624.             Authors' Addresses....................................... 21
  1625.             Acknowledgements......................................... 21
  1626.             References............................................... 21
  1627.             Appendix A: Examples..................................... 22
  1628.             A. 1. Usage Example: Delivery-Time Enabled Mail.......... 22
  1629.             A. 2. Usage Example:  Activation-Time Enabled Mail....... 22
  1630.             Appendix B: Summary of Safe-Tcl Primitives............... 23
  1631.             Appendix C: User-Friendly Renderings..................... 24
  1632.             Appendix D:   Recommendations Regarding untrusted_eval... 25
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.             Borenstein/Rose  Mail-Enabled Applications           Page 29
  1653.  
  1654.